package com.pachong.android.frameworkbase.dialog;

import android.support.annotation.StringRes;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.pachong.android.frameworkbase.dialog.base.IOSAlertBaseFragment;

import com.pachong.android.frameworkbase.R;

/**
 * IOS Style Alert Dialog Fragment
 *
 * @Author: PengWeiwei
 * @E-mail: pengveivei@sina.cn
 * @CreateDate: 2016-06-21
 * @Version: 1.0.0
 */
public class IOSAlertDialogFragment extends IOSAlertBaseFragment {

    private Button mBtnAction;
    private TextView mTvTitle;

    private CharSequence mTitle;
    private CharSequence mActionBtnText;
    private View.OnClickListener mActionBtnListener;


    @Override
    public View createDialogContentView(LayoutInflater inflater) {
        View view =  inflater.inflate(R.layout.fragment_ios_alert_dialog, null);
        mBtnAction = (Button) view.findViewById(R.id.btnAction);
        mTvTitle = (TextView) view.findViewById(R.id.tvTitle);

        if(!TextUtils.isEmpty(mTitle)) {
            mTvTitle.setText(mTitle);
            mTvTitle.setVisibility(View.VISIBLE);
        }

        if(!TextUtils.isEmpty(mActionBtnText)) {
            mBtnAction.setText(mActionBtnText);
        }

        if(mActionBtnListener == null) {
            mActionBtnListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   dismiss();
                }
            };
        }
        mBtnAction.setOnClickListener(mActionBtnListener);
        return view;
    }



    public IOSAlertDialogFragment setTitle(CharSequence title) {
        mTitle = title;
        return this;
    }

    public IOSAlertDialogFragment setTitle(int titleRes) {
        return setTitle(getString(titleRes));
    }



    public IOSAlertDialogFragment setActionButton(CharSequence text, View.OnClickListener listener) {
        mActionBtnListener = listener;
        mActionBtnText = text;
        return this;
    }

    public IOSAlertDialogFragment setActionButton(@StringRes int strId, View.OnClickListener listener) {
        return setActionButton(getString(strId), listener);
    }


    public IOSAlertDialogFragment setActionButton(@StringRes int strId) {
        return setActionButton(getString(strId), null);
    }


    public IOSAlertDialogFragment setActionButton(String text) {
        return setActionButton(text, null);
    }
}
